package com.gdth.bank.widget.baiduMap;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMyLocationClickListener;
import com.baidu.mapapi.map.MyLocationData;

/**
 * 定位监听
 * @author lenovo
 *
 */
public class BBDLocationListener extends BDAbstractLocationListener {
	protected BaiduMap baiduMap;
	
	/**
	 * 定位返回结果
	 */
	public BDLocation mBDLocation;
	
	public BBDLocationListener(BaiduMap baiduMap, OnMyLocationClickListener mOnMyLocationClickListener){
		this.baiduMap = baiduMap;
		
		baiduMap.setOnMyLocationClickListener(mOnMyLocationClickListener); 
	}
	
	@Override
	public void onReceiveLocation(BDLocation location) {
		if (location == null)
			return;
		// 设置定位数据到定位图层上,就是显示当前位置的那个点和圆圈
		MyLocationData locationData = new MyLocationData.Builder()
				.accuracy(location.getRadius())		// 定位的精确度
				.direction(location.getDirection())	// 定位的方向 0~360度
				.latitude(location.getLatitude())	// 经度
				.longitude(location.getLongitude())	// 纬度
                .speed(location.getSpeed()).build();

		baiduMap.setMyLocationData(locationData);
		this.mBDLocation = location;
		if (mLocationseleted != null){
			mLocationseleted.seletedLocaton(this.mBDLocation);
		}
	}
	
	private LocatonSeleted mLocationseleted;
	
	public void setLocatonSeleted(LocatonSeleted mLocationseleted){
		this.mLocationseleted = mLocationseleted;
	}
	
	public interface LocatonSeleted{
		public abstract void seletedLocaton(BDLocation mBDLocation);
	}
}
